//
//  ShellSelectWallertView.m
//  ShellWallert
//
//  Created by lvzhao on 2020/2/14.
//  Copyright © 2020 VV. All rights reserved.
//

#import "ShellSelectWallertView.h"
#import "ShellWallertViewModel.h"

@interface ShellSelectWallertView()


@property (nonatomic,strong) ShellWallertViewModel *viewModel;

//选择的btn
@property (nonatomic,strong) UIButton *selectBtn;

//冻结数量
@property (nonatomic,strong) UILabel *frozenNumLabel;

//可用数量
@property (nonatomic,strong) UILabel *availableNumLabel;

@end

@implementation ShellSelectWallertView

- (instancetype)initViewModel:(LZBaseViewModel *)viewModel
{
    self = [super init];
    if (self) {
        
        self.viewModel = (ShellWallertViewModel *)viewModel;
        [self setupView];
    }
    return self;
}

#pragma mark - setupView
- (void)setupView{

    UIView *currencyView = [[UIView alloc] init];
    [self addSubview:currencyView];
    [currencyView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-24);
        make.width.mas_equalTo(260);
        make.height.mas_equalTo(34);
        make.centerX.mas_equalTo(self.mas_centerX);
    }];
    currencyView.bColor = UIColorHex(0x156097);
    currencyView.bWidth = 0.5;
    currencyView.cornerRadius = 17;
    
    NSArray *titiles = @[@"USDT",@"ETH",@"BTC"];
    for(int i = 0; i < titiles.count; i++){
        UIButton *titleBtn = [UIButton lz_buttonTitle:titiles[i] titleColor:UIColorHex(0x156097) fontSize:16];
        [titleBtn setTitleColor:UIColor.whiteColor forState:UIControlStateSelected];
        [currencyView addSubview:titleBtn];
        [titleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(currencyView.mas_centerY);
            make.width.mas_equalTo(85);
            make.height.mas_equalTo(30);
            make.left.mas_equalTo(2.5 +  i * 85);
        }];
        titleBtn.cornerRadius = 15;
        UIImage *selectImage = [UIImage gradientImageWithColors:@[UIColorHex(0x45B6FF),UIColorHex(0x8EE7F5)] rect:CGRectMake(0, 0, 85, 30)];
        UIImage *normalImage = [UIImage imageWithColor:UIColor.clearColor size:CGSizeMake(85, 30)];

        [titleBtn setBackgroundImage:selectImage forState:UIControlStateSelected];
        [titleBtn setBackgroundImage:normalImage forState:UIControlStateNormal];
        
        if(i == 0){
            titleBtn.selected = YES;
            self.selectBtn = titleBtn;
        }
        [titleBtn addTarget:self action:@selector(currencyBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
   
}


//点击事件
- (void)currencyBtnClick:(UIButton *)sender{
    
    self.selectBtn.selected = NO;
    sender.selected = YES;
    self.selectBtn = sender;
    showLoadingTitle(@"", nil);
    //发送请求
    self.viewModel.currentCurrncy = sender.currentTitle;
    
    [self.viewModel.reloadSubject sendNext:@(5)];
    
    //刷新数据
    [self.viewModel getUserAllCoin];
}

@end
